/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package earleyalgorithm;

/**
 *
 * @author NGOC
 */
public class Category {
    String name;
    boolean terminal;

    /*public static final Category START = new Category("START", false) {
	@Override
	public boolean equals(Object obj) {
            return (this == obj);
	}
    };*/

    public Category(String name) {
	this(name, false);
    }

    public Category(String name, boolean terminal) {
	if(!terminal && (name == null || name.length() == 0)) {
		throw new IllegalArgumentException(
					"empty name specified for category");
	}

	this.name = name;
	this.terminal = terminal;
    }
    public String getName() {
	return name;
    }

    public boolean isTerminal() {
	return terminal;
    }

    @Override
    public boolean equals(Object obj) {
	if(obj instanceof Category) {
		Category oc = (Category)obj;
		return (terminal == oc.terminal && name.equals(oc.name));
	}
	return false;
    }
    @Override
    public int hashCode() {
	return (31 * name.hashCode() * Boolean.valueOf(terminal).hashCode());
    }

    @Override
    public String toString() {
	return (name.length() == 0) ? "<empty>" : name;
    }
}
